package csu.web.mypetstore.web.servlet;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ValidateCodeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setHeader("param", "no-cache");
        resp.setHeader("cache-control", "no-cache");
        resp.setIntHeader("expires", 0);


        ValidateCode validateCode = new ValidateCode(100,30,4,10);
        String codeString =  validateCode.getCode();
        req.getSession().setAttribute("code",codeString);
        System.out.println("====codeString======"+codeString);
        try {
            validateCode.write(resp.getOutputStream());
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
